home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_200 / 227_01 / herc.c < prev    next >
Text File  |  1988-02-07  |  4KB  |  144 lines

  1. /*
  2.  *
  3.  * update history
  4.  * --------------
  5.  * Jun, 5. 1987    function initgraf used wrong port addresses - 0x3b0 changed
  6.  *                 to 0x3b4, 0x3b1 changed to 0x3b5.
  7.  *
  8.  */
  9.  
  10. #include <stdio.h>
  11. #include <dos.h>
  12.  
  13. #define NOLLHINC
  14.  
  15. #include "herc.h"
  16. #include "graphics.h"
  17.  
  18. #ifdef    USEPROTT
  19.     extern void    inton(void);
  20.     extern void    intoff(void);
  21. #endif
  22.  
  23. #ifdef USEVOID
  24. void
  25. #endif
  26. initgraf(autocls)
  27. int autocls;          /* clear graphics screen? (YES/NO) */
  28. /**
  29. * name          initgraf()
  30. *
  31. * synopsis      initgraf(autocls);
  32. *               int autocls; / Should the graphics screen be cleared  /
  33. *                            / after mode-switch?                     /
  34. *
  35. * description   This routine switches the card to graphics mode. Page one is
  36. *               used to display the graphic. There is no page-switch
  37. *               supported! The caller may clear the previous graphic or leave
  38. *               it unchanged (variable "autocls").
  39. *
  40. * warning       This function depends on hardware-parameters!
  41. **/
  42. {
  43. static unsigned char init_par[] = {  /* CRT 6845 register values. */
  44.                                   0x35, 0x2d, 0x2e, 0x07,
  45.                                   0x5b, 0x02, 0x57, 0x57,
  46.                                   0x02, 0x03, 0x00
  47.                                   };
  48. int i;
  49. int cnt;
  50.  
  51. for(cnt = 0 ; cnt < 2 ; ++cnt) /* must be executed twice - I don't know why! */
  52.   {
  53.   if(autocls)           /* clear previous graphic? */
  54.     clrgraph(0);
  55.   intoff();
  56.   outp(CRTPORT, 0);     /* switch off video */
  57.   for(i = 0 ; init_par[i] ; i++)
  58.     {
  59.     outp(0x3b4, i);            /* select register */
  60.     outp(0x3b5, init_par[i]);  /* initialize register */
  61.     }
  62.   outp(MLXPORT, 3);     /* allow graphics-mode */
  63.   outp(CRTPORT, 0xaa);   /* page 1, video */
  64.   inton();
  65.   }
  66. }
  67.  
  68. #ifdef USEVOID
  69. void
  70. #endif
  71. exitgraf()
  72. /**
  73. * name          exitgraf()
  74. *
  75. * synopsis      exitgraf();
  76. *
  77. * description   This routine switches the card back to text-mode. Bios-
  78. *               services (INT 10h, set mode) are used, so it is not
  79. *               guaranteed, that the graphics page isn't destroyed!
  80. **/
  81. {
  82. union REGS regs;
  83.  
  84. regs.x.ax = 0007;
  85. int86(0x10, ®s, ®s);   /* set mode 7 (internal b/w mode) */
  86. }
  87.  
  88. prtgrf()
  89. /**
  90. * name          prtgrf
  91. *
  92. * synopsis      ret = prtgrf();
  93. *               int ret      return -1 if succesful, 0 otherwise
  94. *
  95. * description   This function prints the entire graphics-screen on a
  96. *               dot-matrixprinter. The function was developed using a
  97. *               NEC P6 printer, but should run with litle alteration on
  98. *               every EPSON compatible printer.
  99. *
  100. * warning       This function depends on hardware-parameters!
  101. **/
  102. {
  103. int state;                          /* return value -1 success, 0 failure */
  104. int y;                              /* y-coordinate */
  105. register int yo;                    /* y-offset in mainloop */
  106. int x;                              /* x-coordinate */
  107. register unsigned char prtbyte;     /* printer-byte */
  108. unsigned char buf[720];             /* output buffer */
  109. int lstnon0;                        /* last non-zero byte */
  110. FILE *printer;
  111.  
  112. state = -1;
  113. if((printer = fopen("PRN", "wb")) == NULL)
  114.   state = 0;
  115. else
  116.   {
  117.   fprintf(printer, "%c%c%c", (char) 0x1b, '3', 24);  /* 24 / 180 inch */
  118.   for(y = 0 ; y <= 340 ; y += 8)    /* Bytewise down */
  119.     {
  120.     lstnon0 = -1;
  121.     for(x = 0 ; x < 720 ; x++)     /* all pixel of one row */
  122.       {
  123.       prtbyte = 0;                 /* reset all pixel */
  124.       for(yo = 0 ; yo < 8 ; yo++)  /* 8 rows per byte */
  125.         prtbyte |= (getpixel(x, y+yo) << (7 - yo)); /* set pixel */
  126.       buf[x] = prtbyte;
  127.       if(prtbyte != 0)
  128.         lstnon0 = x;
  129.       }
  130.     if(lstnon0 != -1)
  131.       {
  132.       lstnon0++; /* now number of bytes, not index */
  133.       fprintf(printer, "%c%c%c%c%c", (char) 0x1b, '*', (char) 6,
  134.              (char) (lstnon0 % 256), (char) (lstnon0 / 256));
  135.       fwrite(buf, sizeof(unsigned char), lstnon0, printer);
  136.       }
  137.     fprintf(printer, "\n\r");
  138.     }
  139.   fprintf(printer, "%c%c", (char) 0x1b, '2');  /* 6 lpi - normal */
  140.   }
  141. fclose(printer);
  142. return(state);
  143. }
  144.